namespace System.Xml.Serialization
{
    public abstract class XmlRuntimeSerializer<T> : XmlRuntimeSerializer, IXmlRuntimeSerializer<T>
    {
        private IXmlRuntimeSerializer<T> _runtimeSerializer;

        public XmlRuntimeSerializer()
        {
            Type type = typeof(T);
            _runtimeSerializer = this;
            InitializeRuntimeType(type);
        }

        protected abstract void Write(T value, IXmlPropertyWriter writer, string propertyName);
        protected abstract T Read(IXmlPropertyReader reader, string propertyName);

        #region IXmlRuntimeSerializer<T> Members

        T IXmlRuntimeSerializer<T>.Deserialize(IXmlPropertyReader reader, string propertyName)
        {
            return Read(reader, propertyName);
        }
        void IXmlRuntimeSerializer<T>.Serialize(T value, IXmlPropertyWriter writer, string propertyName)
        {
            Write(value, writer, propertyName);
        }

        #endregion

        public override void Serialize(object value, IXmlPropertyWriter writer, string propertyName)
        {
            _runtimeSerializer.Serialize((T)value, writer, propertyName);
        }
        public override object Deserialize(IXmlPropertyReader reader, string propertyName)
        {
            return _runtimeSerializer.Deserialize(reader, propertyName);
        }
    }
}
